Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
What is causing the Node.js "MaxListenersExceededWarning" warning?

I have this simple Express.js back-end server:

const app = require("express")();
const dotenv = require("dotenv");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");

const swaggerUi = require("swagger-ui-express");
const swaggerJsDocs = require("swagger-jsdoc");

const swaggerOptions = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: 'API',
      version: '0.0.1',
      description: 'Api docs .'
    },
  },
  apis: ["./src/swagger/swagger.yaml"]
};
const swaggerDocs = swaggerJsDocs(swaggerOptions);

dotenv.config();

const server = require("http").createServer(app);

app.use(cookieParser());
app.use(bodyParser.json({limit: '10MB'}));
app.use(bodyParser.urlencoded({extended: true}));
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocs));
app.use("/", require('./src/routes'));

const port = process.env.PORT || 3001;
server.listen(port, () => console.log("API listening on port " + port + "!"));

But I keep getting this warning and I actually have no idea about what is the reason for it. I don't have web sockets or something, but still:

(node:7847) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 
11 uncaughtException listeners added to [process]. 
Use emitter.setMaxListeners() to increase limit
about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

That specific error means that your code (or the modules you are using) have added 11 handlers for the process.on('uncaughtException', ...) event.

This is typically an indication that some code is repeatedly adding the same event handler over and over again (in some other event handler such as inside an Express route) where they accumulate more and more forever. This could be in either your own code or in some module that your code imports.

Event handlers like this should be added only once for a given section of code or should be added, then removed when no longer needed.

Based on the small amount of code you show here, I'd guess that the first place to look would be in ./src/routes for any code that adds an uncaughtException listener in one of your route handlers.

about 4 years ago · Santiago Gelvez Report

0

I have found the reason of this warning.

In this project I use winston and winston-daily-rotate-file, for every controller and service (to write down logs) I create this logger instance, and basically this creates those handlers:

const loggerInstance = createLogger({
  level: process.env.NODE_ENV !== 'production' ? 'debug' : 'info',
  format: combine(
    colorize(),
    json(),
    label({ label: data.label ? data.label : 'NONE' }),
    timestamp(),
    myFormat,
  ),
  transports: transportsConfig,
});

if (process.env.NODE_ENV !== 'production') {
  loggerInstance.add(new transports.Console({
    handleExceptions: true,
  }));
}

if (process.env.DISABLE_LOGGER === 'yes') {
  loggerInstance.silent = true;
}

return loggerInstance;
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!